package server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.UserInfoBase;
import model.UserModel;
import page.PageManagerContractFactory;
import page.PageManagerSMSFactory;
import DBtools.UserBO;
import abstractclass.PageManagerAbstract;

public class ContractShowServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out=resp.getWriter();
		out.println("<html><body><h1>This is a servlet test ContractShowServlet . welcome</h1></body></html>");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String imei = req.getParameter("imei");
		PageManagerContractFactory contractFactory = new PageManagerContractFactory();
		contractFactory.setImei(imei);
		String username = (String) req.getSession().getAttribute("username");
		UserInfoBase info = (UserInfoBase) req.getSession().getAttribute(username);
		if(info==null){
			info = new UserInfoBase();
		}
		UserModel model = new UserModel();
		
		UserBO bo = new UserBO();
		List list = bo.find(username);
		HashMap<String, Object> map = (HashMap<String, Object>) list.get(0);
		model.user = username;
		model.userlevel = (int) map.get("userlevel");
		info.pagename="ͨѶ¼";
		info.pageManeger = (PageManagerAbstract) contractFactory.getPageManager(model);
		info.page = 0;
		info.userlevel = model.userlevel;
		req.getRequestDispatcher("main.jsp").forward(req, resp);
	}

}
